<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 流年 <liu21st@gmail.com>
// +----------------------------------------------------------------------

// 应用公共文件

function get_date()
{
    echo date('Y-m-d H:i:s') . '<br />';
}

function get_category()
{
    // 产品分类
   // if (!$tree = cache('get_category')) {
        $items = db('category')->order('pid asc')->select();
        //dump($items);
        foreach ($items as $item) {
            $tmpMap[$item['id']] = $item;
        }

        foreach ($items as $item) {
            if (isset($tmpMap[$item['pid']])) {
                $tmpMap[$item['pid']]['childrens'][] = &$tmpMap[$item['id']];
            } else {
                $tree[] = &$tmpMap[$item['id']];
            }
        }
        cache('get_category', $tree);
    //}
    //dump($tree);
    return $tree;
}

function get_nav_img($url) {
    return db('nav')->where('url', $url)->value('image');
}

/**
 * 生成验证码
 */
function GetVerify(){
    $Verify = new \verify\Verify();
    $Verify->length   = 4;
    $Verify->entry();
}